//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Coche.h"

void Coche::stepCoche(){
        angulo = angulo + M_PI/14;
        r = r - 45;
        if (r < 0) r = 360;
}
void Coche::antiStepCoche(){
        angulo = angulo - M_PI/14;
        r = (r + 45)%360;
}

void Coche::dibujaCoche(){
glColor3f(0, 0, 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
        glVertex3f( 0.5, 0.5,-0.5);
        glVertex3f(-0.5, 0.5,-0.5);
        glVertex3f(-0.5, 0.5, 0.5);
        glVertex3f( 0.5, 0.5, 0.5);
glEnd();
glBegin(GL_POLYGON);
        glVertex3f( 0.5,-0.5, 0.5);
        glVertex3f(-0.5,-0.5, 0.5);
        glVertex3f(-0.5,-0.5,-0.5);
        glVertex3f( 0.5,-0.5,-0.5);
glEnd();
glBegin(GL_POLYGON);
        glVertex3f( 0.5, 0.5, 0.5);
        glVertex3f(-0.5, 0.5, 0.5);
        glVertex3f(-0.5,-0.5, 0.5);
        glVertex3f( 0.5,-0.5, 0.5);
glEnd();
glBegin(GL_POLYGON);
        glVertex3f( 0.5,-0.5,-0.5);
        glVertex3f(-0.5,-0.5,-0.5);
        glVertex3f(-0.5, 0.5,-0.5);
        glVertex3f( 0.5, 0.5,-0.5);
glEnd();
glBegin(GL_POLYGON);
        glVertex3f(-0.5, 0.5, 0.5);
        glVertex3f(-0.5, 0.5,-0.5);
        glVertex3f(-0.5,-0.5,-0.5);
        glVertex3f(-0.5,-0.5, 0.5);
glEnd();
glBegin(GL_POLYGON);
        glVertex3f( 0.5, 0.5,-0.5);
        glVertex3f( 0.5, 0.5, 0.5);
        glVertex3f( 0.5,-0.5, 0.5);
        glVertex3f( 0.5,-0.5,-0.5);
glEnd();


glPushMatrix();
        glTranslatef(0.5,0.5, 0.5);
        glRotatef(90,0,1,0);
        dibujarCilindros();
glPopMatrix();
glPushMatrix();
        glTranslatef(0.5,0.5, -0.5);
        glRotatef(90,0,1,0);
        dibujarCilindros();
glPopMatrix();
glPushMatrix();
        glTranslatef(-0.65,0.5, 0.5);
        glRotatef(90,0,1,0);
        dibujarCilindros();
glPopMatrix();
glPushMatrix();
        glTranslatef(-0.65,0.5, -0.5);
        glRotatef(90,0,1,0);
        dibujarCilindros();
glPopMatrix();

};

void Coche::dibujarCilindros(){ 
        glPushMatrix();
                glScalef(0.15,0.15,0.15);
                GLUquadric* cilindro=gluNewQuadric();
                GLUquadric* disco=gluNewQuadric();
                gluQuadricDrawStyle(cilindro, GLU_FILL);
                gluQuadricDrawStyle(disco, GLU_FILL);
                glRotatef(r,0.0,0.0,1.0);
                glColor3f(0.8, 0.0, 0.0);
                gluCylinder(cilindro, 1.5, 1.5, 1.5, 20, 20);
                glColor3f(0.0,0.8,0.0);
                gluPartialDisk(disco,0, 1.5, 20, 20,45,45);
                glTranslatef(0.0,0.0,1.5);
                gluPartialDisk(disco,0, 1.5, 20, 20,45,45);
    glPopMatrix();
};
//---------------------------------------------------------------------------

#pragma package(smart_init)
